package cn.edu.xmu.javaee.productdemojpa.mapper.join.po;

import cn.edu.xmu.javaee.productdemojpa.mapper.separate.po.ProductPo;
import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;
import org.springframework.data.annotation.CreatedBy;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedBy;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import java.time.LocalDateTime;
import java.util.List;

/**
 * 商品规格
 * @author Ming Qiu
 **/
@Data
@NoArgsConstructor
@AllArgsConstructor
@ToString
@Entity
@Table(name="goods_product")
@EntityListeners(AuditingEntityListener.class)
public class JoinProductPo {

    /**
     * 代理对象
     */
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    private Long shopId;

    @ManyToMany
    @JoinTable(name = "goods_goods",
                joinColumns = @JoinColumn(name="product_id"),
                inverseJoinColumns = @JoinColumn(name = "relate_product_id"))
    @ToString.Exclude
    private List<ProductPo> otherProduct;

    @OneToMany(mappedBy = "product")
    @ToString.Exclude
    private List<JoinOnSalePo> onSaleList;

    private String name;

    private Long originalPrice;

    private Long weight;

    private String barcode;

    private String unit;

    private String originPlace;

    @CreatedBy
    @Column(updatable = false)
    private String creator;

    @LastModifiedBy
    @Column(insertable = false)
    private String modifier;

    @CreatedDate
    @Column(insertable = false, updatable = false)
    private LocalDateTime gmtCreate;

    @LastModifiedDate
    @Column(insertable = false)
    private LocalDateTime gmtModified;

    private Integer commissionRatio;

    private Long freeThreshold;

    private Byte status;

}
